package StudyCode.summary.mycollection;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ImplementsComparableInterface implements Comparable {
	private String id;
	private String name;
	private double retail;
	private int quantity;
	private double price;

	ImplementsComparableInterface(String idIn, String nameIn, String retailIn, String quanIn) {
		id = idIn;
		name = nameIn;
		retail = Double.parseDouble(retailIn);
		quantity = Integer.parseInt(quanIn);

		if (quantity > 400)
			price = retail * .5D;
		else if (quantity > 200)
			price = retail * .6D;
		else
			price = retail * .7D;
		price = Math.floor(price * 100 + .5) / 100;
	}

	@Override
	public int compareTo(Object obj) {
		ImplementsComparableInterface temp = (ImplementsComparableInterface) obj;
		if (this.price < temp.price)
			return 1;
		else if (this.price > temp.price)
			return -1;
		return 0;
	}

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public double getRetail() {
		return retail;
	}

	public int getQuantity() {
		return quantity;
	}

	public double getPrice() {
		return price;
	}
}
